package com.zys.controller;


import com.zys.test.WeChatUser;
import com.zys.test.WechatUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;


@Controller
@Slf4j
public class TestController {

    @GetMapping("/login")
    public String loginPage() {
        return "login"; // 返回登录页面模板
    }

    @GetMapping("/test/wxCallback")
    public String wxCallback(String code, String state, HttpServletRequest request
            , HttpServletResponse response) throws Exception {
        response.setContentType("text/html;charset=UTF-8"); // 关键设置
        WeChatUser userInfo = WechatUtil.getUserInfo(code);
        request.setAttribute("userInfo", userInfo);
        return "callback"; // 确保返回的是模板名称（不带.html）
    }

}
